<?php
include_once("../config.php");


$order_info['order_id']="4964";

$order=select_one_line_all_items($table_prefix."order_info",
                              "order_id = '{$order_info['order_id']}'");

print_r2($order);

$_schedule=select_lines_all_items($table_Prefix . 'product_schedule',
                                  'apply_date asc',
                                  "product_nid = '{$order['product_id']}'","");





//提取订单日期，用于循环生成detail
$order_startdate = $order['startdate'];
$order_enddate   = $order['enddate'];
$order_adddate   = $order['add_date']; //用户下单的时间

foreach ($_schedule as $schedule)
{
    $_order_detail['ai_order_nid'] = $order['order_id'];
    $_order_detail['ai_ondate'] = $schedule['apply_date'];
    $_order_detail['ai_product_nid'] = $order['product_id'];
    $_order_detail['ai_student_nid'] = $order['student_nid'];
    $_order_detail['ai_user_nid'] = $order['user_id'];
    $_order_detail['ai_name'] = $order['student_name'];
    $_order_detail['ai_price'] = "0.0";
    $_order_detail['ai_number'] = "1";
    //$i是循环到的日期
    //如果下单时间=$i 或者>$i，意味着迟于开始服务的时间，则状态为未配送。
    if ($order_adddate >= $schedule['apply_date'])
    {
        $_order_detail['ai_status'] = "T+1未配送";
    }
    else
    {
        $_order_detail['ai_status'] = "正常";
    }
    $_order_detail['ai_product_name'] = $schedule['milk_name'];
    $_order_detail['ai_order_name'] = $order['order_name'];
    $_order_detail['ai_add_date'] = date("Y-m-d H:i:s"); // 当前日期和时间
    $_order_detail['ai_school'] = $order['student_school'];
    $_order_detail['ai_grade']  = $order['student_grade'];
    $_order_detail['ai_class_'] = $order['student_class'];

    echo $sql=insert_data($table_prefix."order_detail",$_order_detail);

    echo "<br/>";

}





    ?>